﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentSystem
{
    


    class Teather
    {
        public static void TeatherSystem()
        {
            Drawing.teatherinterface();
            int enterNumber;
           
            bool flage = false;
            do
            {
                if (flage)
                {
                    Console.Write("输入错误，请重新输入需要操作的编号:");
                }
                else
                {
                    Console.Write("请输入操作数字：");
                }
                flage = false;
                while (!int.TryParse(Console.ReadLine(), out enterNumber))
                {
                    Console.Write("\n输入错误，请重新输入:");
                }

                switch (enterNumber)
                {
                    case 1: showStudentsInformation(); return;
                    case 2:
                        showStudentsInformation();return;
                    case 3:  EnterStudentBasicInformation();return;
                    case 4:
                        EnterStudentBasicInformation();return;
                    case 5: Login_Interface.landingRole();break;
                    case 6: Environment.Exit(0); break;
                    default:
                        flage = true;
                        break;
                }
                
            } while (flage);

        }
        static List<Student> myList = new List<Student>();

        public static void EnterStudentBasicInformation()
        {
            bool flage=false;
            bool flageid = false;
            bool flagesex= false;
            bool flageScore = false;
            int id;
            int sex;
            float score;
            
            do
            {
                Student student=new Student();
                do
                {
                    if (flageid)
                    {
                        Console.Write("输入错误，请重新输入需要输入学生ID:");
                    }
                    else
                    {
                        Console.Write("请输入学生ID：");
                    }
                    flageid = false;
                    while (!int.TryParse(Console.ReadLine(), out id))
                    {
                        Console.Write("\n输入错误，请重新输入ID:");
                        flageid = true;
                    }
                } while (flageid);//ID

            Console.WriteLine("输入学生名称");
            string name = Console.ReadLine();
            
                do
            {
                if (flagesex)
                {
                    Console.Write("输入错误，请重新输入输入学生性别 1.男生 2.女生");
                }
                else
                {
                    Console.Write("输入学生性别 1.男生 2.女生: ");
                }
                flagesex = false;
                while ((!int.TryParse(Console.ReadLine(), out sex))&&(sex==1||sex==2))
                {
                    Console.Write("\n输入错误，请重新输入学生性别 1.男生 2.女生");
                    flagesex = true;
                }
            } while (flagesex);

            do
            {
                if (flageScore)
                {
                    Console.Write("输入错误，请重新输入学生的分数:");
                }
                else
                {
                    Console.Write("请输入输入学生的分数:");
                }
                flageScore = false;
                while (!float.TryParse(Console.ReadLine(), out score))
                {
                    Console.Write("\n输入错误，请重新输入学生的分数:");
                    flageScore= true;
                }
            } while (flageScore);
            
            student.Name = name;
            student.ID = id;
            student.SEX = sex;
            student.Score = score;
                
            myList.Add(student);flage = false;
            Console.WriteLine("是否继续输入学生信息？ Y:继续输入，按其他键返回");
                string YN = Console.ReadLine();
                if (YN=="Y"||YN=="y")
                {
                    flage = true;
                }
                
            } while (flage);
            TeatherSystem();
        }

        public static void showStudentsInformation()
        {
            Console.WriteLine("\n已录入学生信息");
            foreach (var temp in myList)
            {
                Console.WriteLine(temp);
            }
            Console.WriteLine("按回车返回上层");
            Console.ReadKey();
            TeatherSystem();
        }
    }
}
